package redis

import (
	"context"
	"dou/config"
	"dou/global"
	"fmt"
	"github.com/go-redis/redis/v8"
	"log"
)

func InitRedis() {
	re := config.AppConf.RedisConfig
	addr := fmt.Sprintf("%s:%d", re.Host, re.Port)
	global.Client = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	_, err := global.Client.Ping(context.Background()).Result()
	if err != nil {
		panic("redis link fail")
	}
	log.Println("redis link success")
}
